//
//  OilCarStatusListCell.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/20.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "OilCarStatusListCell.h"

@interface OilCarStatusListCell ()


@end

@implementation OilCarStatusListCell

- (void)awakeFromNib {
  [super awakeFromNib];
  // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    [self createViews];
  }
  return self;
}

- (void)createViews {
  ///!
  _carLogoImageView = [[UIImageView alloc] init];
  [self.contentView addSubview:_carLogoImageView];
  ///!
  _oilNumberLabel = [[UILabel alloc] init];
  _oilNumberLabel.textAlignment = NSTextAlignmentLeft;
  _oilNumberLabel.font = [UIFont systemFontOfSize:11];
  [self.contentView addSubview:_oilNumberLabel];
  
  _carNumberLabel = [[UILabel alloc] init];
  _carNumberLabel.textAlignment = NSTextAlignmentLeft;
  _carNumberLabel.font = _oilNumberLabel.font;
  [self.contentView addSubview:_carNumberLabel];
  
  _phoneNumberLabel = [[UILabel alloc] init];
  _phoneNumberLabel.textAlignment = NSTextAlignmentLeft;
  _phoneNumberLabel.font = _oilNumberLabel.font;
  [self.contentView addSubview:_phoneNumberLabel];
  
  
  _statusButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
  ///! 停用
  [_statusButton setImage:[UIImage imageNamed:@"Oil_car_State_Stoping"] forState:UIControlStateNormal];
//  ///! 启用
  [_statusButton setImage:[UIImage imageNamed:@"Oil_car_State_Useing"] forState:UIControlStateSelected];
//  ///! 拒绝
  [_statusButton setImage:[UIImage imageNamed:@"Oil_car_State_Refuseing"] forState:UIControlStateDisabled];
  [self.contentView addSubview:_statusButton];

  _statusLabel = [[UILabel alloc] init];
  _statusLabel.font = [UIFont systemFontOfSize:8.0f];
  _statusLabel.textAlignment = NSTextAlignmentCenter;
  [self.contentView addSubview:_statusLabel];
  
  _lineView = [[UIView alloc] init];
  _lineView.backgroundColor = HEXCOLOR(0xf6f6f6);
  [self.contentView addSubview:_lineView];
  
  [_carLogoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.contentView.mas_leading).offset(20);
    make.top.mas_equalTo(self.contentView.mas_top).offset(20);
    make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-20);
    make.width.mas_equalTo(self.carLogoImageView.mas_height);
  }];
  
  [_oilNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.carLogoImageView.mas_trailing).offset(20);
    make.top.mas_equalTo(self.contentView.mas_top).offset(10);
    make.height.mas_equalTo(@15);
    make.trailing.mas_equalTo(self.contentView.mas_trailing).offset(-60);
  }];
  
  [_carNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.height.mas_equalTo(self.oilNumberLabel);
    make.top.mas_equalTo(self.oilNumberLabel.mas_bottom).offset(5);
  }];
  
  [_phoneNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.height.mas_equalTo(self.carNumberLabel);
    make.top.mas_equalTo(self.carNumberLabel.mas_bottom).offset(5);
  }];
  
  [_statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
    make.width.mas_equalTo(@10);
    make.height.mas_equalTo(@10);
    make.centerY.mas_equalTo(self.contentView.mas_centerY);
    make.trailing.mas_equalTo(self.contentView.mas_trailing).offset(-15);
  }];
  
  [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(self.statusButton.mas_bottom).offset(3);
    make.height.mas_equalTo(@10);
    make.width.mas_equalTo(@30);
    make.centerX.mas_equalTo(self.statusButton);
  }];
  
  [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.contentView.mas_leading).offset(10);
    make.trailing.mas_equalTo(self.contentView.mas_trailing).offset(-10);
    make.height.mas_equalTo(@1);
    make.bottom.mas_equalTo(self.contentView.mas_bottom);
  }];
  
}


- (void)setupData:(id)data {
  
  
  _oilNumberLabel.text = [NSString stringWithFormat:@"%@:  %@",YTLocalizedString(@"油咭编号"),@"8937 4957 3744 3589 3881"];
  
  _carNumberLabel.text = [NSString stringWithFormat:@"%@:  %@",YTLocalizedString(@"车牌号码"),@"FV1025"];
  
  _phoneNumberLabel.text = [NSString stringWithFormat:@"%@:  %@",YTLocalizedString(@"手机号码"),@"9545 0440"];
  
  NSIndexPath *indexPath = data;
  if (indexPath.row == 0) {
    _carLogoImageView.image = [UIImage imageNamed:@"caltex"];

    _statusButton.selected = YES;
    _statusLabel.text = YTLocalizedString(@"启用");
    _statusLabel.textColor = DEF_BLACK;
  
  } else if (indexPath.row == 1) {
    _carLogoImageView.image = [UIImage imageNamed:@"esso"];

    _statusButton.selected = NO;
    _statusLabel.text = YTLocalizedString(@"停用中");
    _statusLabel.textColor = DEF_RED;
  
  } else {
    _carLogoImageView.image = [UIImage imageNamed:@"美孚"];

    _statusButton.enabled = NO;
    _statusLabel.text = YTLocalizedString(@"拒绝");
    _statusLabel.textColor = DEF_GRAY;
  }
  
}



@end

